package Duotai;

public class Test {
    public static void main(String[] args) {
        show(new Cat());
        show(new Dog());

        dongwu_1 c = new Cat();  //父类调用Cat类里面的方法; 向上转型
        c.eat();
        Cat a = (Cat)c;   //将父类中对象强制转换到Cat中;  向下转型
        a.work();

    }
    //定义一个show方法
    public static void show(dongwu_1 a){
        a.eat();
        if (a instanceof Cat){
            Cat c = (Cat)a;
            c.work();
        }else if (a instanceof Dog){
            Dog c= (Dog)a;
            c.work();
        }
    }
}

//定义一个动物类
abstract class dongwu_1{
    abstract void eat();
}
//定义一个猫类
class Cat extends dongwu_1{
    public void eat(){
        System.out.println("吃鱼");
    }
    public void work(){
        System.out.println("抓老鼠");
    }
}
//定义一个狗类
class Dog extends dongwu_1{
    public void eat(){
        System.out.println("啃骨头");
    }
    public void work(){
        System.out.println("看家");
    }
}






















